package com.googlecode.dtools.typeinfo.work.impl;

import com.googlecode.dtools.typeinfo.beans.DmType;
import com.googlecode.dtools.typeinfo.dao.DmTypeDAO;
import com.googlecode.dtools.typeinfo.work.FilesWorker;
import com.googlecode.dtools.typeinfo.work.ListWorker;
import com.googlecode.dtools.typeinfo.work.TransformBean;
import com.googlecode.dtools.typeinfo.work.Worker;
import org.apache.log4j.helpers.Transform;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: A_Reshetnikov
 * Date: 10.06.11
 * Time: 16:21
 * To change this template use File | Settings | File Templates.
 */
public class WorkerImpl implements Worker{


    public FilesWorker getFilesWorker() {
        return filesWorker;
    }

    private FilesWorker filesWorker;

    public DmTypeDAO getDmTypeDAO() {
        return dmTypeDAO;
    }

    private DmTypeDAO dmTypeDAO;
     private ListWorker listWorker;

    public void setTransformBean(TransformBean transformBean) {
        this.transformBean = transformBean;
    }

    private TransformBean transformBean;


    public void work() {
        List<String> list = listWorker.getListForProcessing();
        System.out.println("list.size() = " + list.size());
        processList(list);

    }

    public void processSingle(String dmTypeName) {
       DmType dmType = dmTypeDAO.getDmTypeInfo(dmTypeName);
        transformBean.transform(dmType);
        filesWorker.saveXml(dmType);
        System.out.println("Saved " + dmType.getName() + ".xml");
    }

    public void processList(List<String> list) {
        for (String s: list){
         //   if (typeListFromDocbase && !s.startsWith("dm"))    //todo exclude list
            processSingle(s);
        }
    }

    public void setOutputPath(String path) {
       //todo
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setFilesWorker(FilesWorker filesWorker) {
        this.filesWorker = filesWorker;
    }

    public void setDmTypeDAO(DmTypeDAO dmTypeDAO) {
        this.dmTypeDAO = dmTypeDAO;
    }



    public void setListWorker(ListWorker listWorker) {
        this.listWorker = listWorker;
    }
}
